using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace DataHelper.BLL
{
    public class News
    {
        public int ID { get; set; }
        public int LangID { get; set; }
        public int TypeID { get; set; }
        public string Title { get; set; }
        public string Link { get; set; }
        public string Description { get; set; }
        public string Content { get; set; }
        public string Image { get; set; }
        public string RefLink { get; set; }
        public string SEO { get; set; }
        public DateTime CreatedDate { get; set; }
        public string CreatedUser { get; set; }
        public DateTime UpdatedDate { get; set; }
        public string UpdatedUser { get; set; }
        public bool IsPin { get; set; }
        public bool IsDeleted { get; set; }

        #region NewsSelectAll
        public static List<News> NewsSelectAll(string strSearch="",int top = 1, int bottom = 20, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.News.NewsSelectAll(strSearch,top,bottom,ConnectionString);
            List<News> NewsList = new List<News>();
            while(dr.Read())
            {
                News myNews = new News
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    LangID = !dr.IsDBNull(dr.GetOrdinal("LangID")) ? (int)dr["LangID"] : 0,
                    TypeID = !dr.IsDBNull(dr.GetOrdinal("TypeID")) ? (int)dr["TypeID"] : 0,
                    Title = !dr.IsDBNull(dr.GetOrdinal("Title")) ? (string)dr["Title"] : null,
                    Link = !dr.IsDBNull(dr.GetOrdinal("Link")) ? (string)dr["Link"] : null,
                    Description = !dr.IsDBNull(dr.GetOrdinal("Description")) ? (string)dr["Description"] : null,
                    Content = !dr.IsDBNull(dr.GetOrdinal("Content")) ? (string)dr["Content"] : null,
                    Image = !dr.IsDBNull(dr.GetOrdinal("Image")) ? (string)dr["Image"] : null,
                    RefLink = !dr.IsDBNull(dr.GetOrdinal("RefLink")) ? (string)dr["RefLink"] : null,
                    SEO = !dr.IsDBNull(dr.GetOrdinal("SEO")) ? (string)dr["SEO"] : null,
                    CreatedDate = !dr.IsDBNull(dr.GetOrdinal("CreatedDate")) ? (DateTime)dr["CreatedDate"] : DateTime.Now,
                    CreatedUser = !dr.IsDBNull(dr.GetOrdinal("CreatedUser")) ? (string)dr["CreatedUser"] : null,
                    UpdatedDate = !dr.IsDBNull(dr.GetOrdinal("UpdatedDate")) ? (DateTime)dr["UpdatedDate"] : DateTime.Now,
                    UpdatedUser = !dr.IsDBNull(dr.GetOrdinal("UpdatedUser")) ? (string)dr["UpdatedUser"] : null,
                    IsPin = !dr.IsDBNull(dr.GetOrdinal("IsPin")) ? (bool)dr["IsPin"] : false,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false
                };
                NewsList.Add(myNews);
        }
        dr.Close();
        dr.Dispose();
        return NewsList;
        }
        #endregion
        #region NewsSelectRow
        public static News NewsSelectRow(int ID, int LangID, SqlTransaction ConnectionString = null)
        {
            IDataReader dr = DataHelper.DAL.News.NewsSelectRow(ID, LangID, ConnectionString);
            News news = null;

            if(dr.Read())
            {
                news= new News
                {
                    ID = !dr.IsDBNull(dr.GetOrdinal("ID")) ? (int)dr["ID"] : 0,
                    LangID = !dr.IsDBNull(dr.GetOrdinal("LangID")) ? (int)dr["LangID"] : 0,
                    TypeID = !dr.IsDBNull(dr.GetOrdinal("TypeID")) ? (int)dr["TypeID"] : 0,
                    Title = !dr.IsDBNull(dr.GetOrdinal("Title")) ? (string)dr["Title"] : null,
                    Link = !dr.IsDBNull(dr.GetOrdinal("Link")) ? (string)dr["Link"] : null,
                    Description = !dr.IsDBNull(dr.GetOrdinal("Description")) ? (string)dr["Description"] : null,
                    Content = !dr.IsDBNull(dr.GetOrdinal("Content")) ? (string)dr["Content"] : null,
                    Image = !dr.IsDBNull(dr.GetOrdinal("Image")) ? (string)dr["Image"] : null,
                    RefLink = !dr.IsDBNull(dr.GetOrdinal("RefLink")) ? (string)dr["RefLink"] : null,
                    SEO = !dr.IsDBNull(dr.GetOrdinal("SEO")) ? (string)dr["SEO"] : null,
                    CreatedDate = !dr.IsDBNull(dr.GetOrdinal("CreatedDate")) ? (DateTime)dr["CreatedDate"] : DateTime.Now,
                    CreatedUser = !dr.IsDBNull(dr.GetOrdinal("CreatedUser")) ? (string)dr["CreatedUser"] : null,
                    UpdatedDate = !dr.IsDBNull(dr.GetOrdinal("UpdatedDate")) ? (DateTime)dr["UpdatedDate"] : DateTime.Now,
                    UpdatedUser = !dr.IsDBNull(dr.GetOrdinal("UpdatedUser")) ? (string)dr["UpdatedUser"] : null,
                    IsPin = !dr.IsDBNull(dr.GetOrdinal("IsPin")) ? (bool)dr["IsPin"] : false,
                    IsDeleted = !dr.IsDBNull(dr.GetOrdinal("IsDeleted")) ? (bool)dr["IsDeleted"] : false,

                };
            }
        dr.Close();
        dr.Dispose();
        return news;
        }
        #endregion
        #region NewsInsertRow
        public static void NewsInsertRow(int ID, int LangID, int TypeID, string Title, string Link, string Description, string Content, string Image, string RefLink, string SEO, DateTime CreatedDate, string CreatedUser, DateTime UpdatedDate, string UpdatedUser, bool IsPin, bool IsDeleted, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.News.NewsInsertRow(ID, LangID, TypeID, Title, Link, Description, Content, Image, RefLink, SEO, CreatedDate, CreatedUser, UpdatedDate, UpdatedUser, IsPin, IsDeleted, ConnectionString);
        }
        #endregion
        #region NewsUpdateRow
        public static void NewsUpdateRow(int ID, int LangID, int TypeID, string Title, string Link, string Description, string Content, string Image, string RefLink, string SEO, DateTime CreatedDate, string CreatedUser, DateTime UpdatedDate, string UpdatedUser, bool IsPin, bool IsDeleted, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.News.NewsUpdateRow(ID, LangID, TypeID, Title, Link, Description, Content, Image, RefLink, SEO, CreatedDate, CreatedUser, UpdatedDate, UpdatedUser, IsPin, IsDeleted, ConnectionString);
        }
        #endregion
        #region NewsDeleteRow
        public static void NewsDeleteRow(int ID, int LangID, SqlTransaction ConnectionString = null)
        {
            DataHelper.DAL.News.NewsDeleteRow(ID, LangID,ConnectionString);
        }
        #endregion
    }
}
